/*
 * ============================================================================
 *
 *       Filename:  common.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2015年01月15日 16时03分28秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * ============================================================================
 */
#include <stdio.h>
#include <stdint.h>
#include <errno.h>

#include <netinet/tcp.h>
#include <netdb.h>

#include "common.h"
#include "log.h"

void fllush_stdin()
{
	int c;
	while ( (c = getchar()) != '\n' && c != EOF ) { }
}

char *getmacstr(unsigned char *mac)
{
	char *macstr = ss_malloc(MACSTR_LEN);
	sprintf(macstr, "%02x:%02x:%02x:%02x:%02x:%02x",
		(mac)[0],(mac)[1],(mac)[2],
		(mac)[3],(mac)[4],(mac)[5]); 		
	return macstr;
}

void *ss_malloc(size_t size)
{
	void *tmp = malloc(size);
	if (tmp == NULL)
		exit(EXIT_FAILURE);
	memset(tmp, 0, size);
	return tmp;
}

void *ss_realloc(void *ptr, size_t new_size)
{
	void *new = realloc(ptr, new_size);
	if (new == NULL) {
		free(ptr);
		ptr = NULL;
		exit(EXIT_FAILURE);
	}
	return new;
}
